package com.leetcode.search;

/**
 * date:
 * description:
 */
public class PeakElement {

    public static int findPeakElement(int[] nums) {
        int n = nums.length;
        int l = 0, r = n - 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (nums[mid] > nums[mid + 1]) {
                r = mid;
            }else if(nums[mid] < nums[mid + 1]) {
                l = mid + 1;
            }else{
                l = mid + 1;
            }
        }
        return r;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,1};
        int res = findPeakElement(nums);
        System.out.println(res);
    }
}
